package com.coin900.coin.cmd.coin_coin;

import com.coin900.coin.cmd.ACmd;
import com.coin900.coin.cmd.CmdSign;
import com.coin900.coin.code.CmdCode;
import com.coin900.coin.persist.coin.CoinCoinVO;
import com.coin900.coin.service.coin.ICoinCoinService;
import com.google.gson.Gson;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 列表可以用于支付的币的列表
 *
 * @author shui
 * @create 2018-01-2
 **/
@Controller
public class CoinCoinPayforTokenListAllCmd extends ACmd {
    @Override
    public CmdSign execute(HttpServletRequest request, CmdSign sign) throws Exception {
        CmdSign respSign = new CmdSign(sign);
        String source = sign.getSource();
        JSONObject jsonObject = JSONObject.fromObject(source);
        Long tokenId = Long.parseLong(jsonObject.getString("tokenId"));
        Map<String, Object> params = new HashMap<>();
        params.put("payforTokenStatus", 1);
        params.put("dataStatus", 1);
        params.put("tokenId", tokenId);
        List<CoinCoinVO> coinCoinVOS = this.coinCoinService.loadCoinCoinPayforTokenAll(params);
        Gson gson = new Gson();
        source = gson.toJson(coinCoinVOS);
        respSign.setSource(source);
        return respSign;
    }

    @Autowired
    private ICoinCoinService coinCoinService;

    @Override
    public String getCmdCode() {
        return CmdCode.COIN_COIN_PAYFOR_TOKEN_LIST_ALL;
    }
}
